﻿@model IEnumerable<ADIGRE.MVC3.Web.Controllers.ViewModels.EntradaViewModel>
@using ADIGRE.Domain
@{
    ViewBag.Title = "Cultos";
    Layout = "~/Views/Shared/_LayoutLogado.cshtml";
    int mes = 0;
    int ano = 0;
}
@if (EnumPerfilAcesso.Tesoureiro.Equals((EnumPerfilAcesso)ViewBag.EnumPerfilAcesso))
{
    <p>
        @Html.ActionLink("Registrar Culto", "Culto", null, new { @class = "btn-gold" })
    </p>
}
<center>
    @foreach (var itemAno in Model.Select(x => x.DtCulto.Value.Year).Distinct())
    {
        <div class="ano">
            <span class="ano-data">@string.Format("{0}", itemAno)</span> <span class="ano-valor">@string.Format("(R${0:N2})", Model.Where(x => x.DtCulto.Value.Year == itemAno).Sum(x => x.VlTotal))</span>
        </div>
        foreach (var itemMes in Model.Where(m => m.DtCulto.Value.Year == itemAno).Select(x => x.DtCulto.Value.Month).Distinct())
        {
            
        <div class="mes">
            <span>@string.Format("{0:MMMM}", DateTime.Parse(itemMes + "/" + itemAno))</span>
        </div>
        
        <table class='tEntrada' cellpadding='0' cellspacing='0'>
            <tr>
                <th class="entrada-culto">
                    Culto
                </th>
                <th class="entrada-oferta">
                    Ofertas
                </th>
                <th class="entrada-dizimo">
                    Dízimos
                </th>
                <th class="entrada-total">
                    Total
                </th>
            </tr>
            @foreach (var item in Model.Where(x => x.DtCulto.Value.Year == itemAno && x.DtCulto.Value.Month == itemMes))
            {
                <tr>
                    <td align="center">
                        @string.Format("{0:dd/MM/yyyy}", item.DtCulto)
                    </td>
                    <td align="right">
                        @string.Format("R${0:N2}", item.VlOfertas)
                    </td>
                    <td align="right">
                        @string.Format("R${0:N2}", item.VlDizimos)
                    </td>
                    <td align="right">
                        @string.Format("R${0:N2}", item.VlTotal)
                    </td>
                </tr>
                foreach (var dizimo in item.Dizimos)
                {
                <tr class="dizimista">
                    <td align="left" colspan="2">
                        @string.Format("{0}", (!string.IsNullOrWhiteSpace(dizimo.Dizimista.NmPessoa)) ? dizimo.Dizimista.NmPessoa : "Anônimo")
                    </td>
                    <td align="right">@Html.DisplayFor(d => dizimo.VlLancamento)
                    </td>
                    <td align="center" class="mes">@string.Format("{0:MMMM} de {0:yyyy}", dizimo.DtReferencia)
                    </td>
                </tr>
                }
            }
            <tr class="entrada-mensal">
                <td align="left">
                    Mensal
                </td>
                <td align="right">
                    @string.Format("R${0:N2}", Model.Where(x => x.DtCulto.Value.Year == itemAno && x.DtCulto.Value.Month == itemMes).Sum(x => x.VlOfertas))
                </td>
                <td align="right">
                    @string.Format("R${0:N2}", Model.Where(x => x.DtCulto.Value.Year == itemAno && x.DtCulto.Value.Month == itemMes).Sum(x => x.VlDizimos))
                </td>
                <td align="right">
                    @string.Format("R${0:N2}", Model.Where(x => x.DtCulto.Value.Year == itemAno && x.DtCulto.Value.Month == itemMes).Sum(x => x.VlTotal))
                </td>
            </tr>
        </table>
        
        }
    }
</center>
@section Style {
    <style type="text/css">
        .ano { font-family: Arial; width: 70%; font-size: 22px; border-bottom: 3px solid black; float: left; margin: 0 15% 2% 15%; }
        .ano-data { float: left; margin-left: 15%; }
        .ano-valor { font-size: 16px; float: right; }
        .mes { width: 50%; font-family: Arial; font-size: 18px; font-weight: bold; text-transform: capitalize; margin-top: 2%; }
        
        .tEntrada { width: 60%; border: 1px solid Gray; font-family: Arial; font-size: 14px; }
        .tEntrada td { border-top: 1px solid Gray; padding: 3px; width: 25%; }
        .dizimista td { border: none; padding: 0.2em; font-size: 12px; text-transform: capitalize; }
        .dizimista .mes { color: #8A0808; font-style: italic; }
        .entrada-mensal { font-weight: bold; }
        tr:last-child { background: #81F781; }
    </style>
}
@section Script {}
